<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>23.获取url中的参数</title>
</head>
<body>
  <script>
    const search = loaction.search
    console.log(loaction.search); // ?a=1&b=2

    function urlParams() {
      const res = {}

      const search = location.search.substr(1)
      search.split('&').forEach(item => {
        const arr = item.split('=')
        const key = arr[0]
        const value = arr[1]
        res[key] = value
      })
    }

    // 2.URLSearchParams
    let params = new URLSearchParams(search)
    params.get(key)

  </script>
</body>
</html>